package com.hyc.myvideo.data.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.ButterKnife;
import com.hyc.myvideo.R;
import com.hyc.myvideo.data.adapter.base.BaseListAdapter;
import com.hyc.myvideo.data.api.model.Column;
import com.hyc.myvideo.utils.imguitl.ImgUitl;
import java.util.List;
import timber.log.Timber;

/**
 * 专栏
 * Created by dfeads on 2017/7/28.
 */

public class ColumnAdapter extends BaseListAdapter<Column> {

  public ColumnAdapter(Context context, List<Column> objects) {
    super(context, objects);
  }

  @NonNull @Override
  public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
    ColumnHolder holder;
    Timber.e("==getItemViewType(position)===="+getItemViewType(position));
    if (convertView == null) {
      if (getItemViewType(position) == 0) {
        holder = new ColumnHolder();
        convertView = inflater.inflate(R.layout.adapter_itme_no, parent, false);
        holder.noDataRootLayout = (LinearLayout) convertView.findViewById(R.id.r_no_id);
      } else {
        convertView = inflater.inflate(R.layout.item_column, parent, false);
        holder = new ColumnHolder(convertView);
      }
      convertView.setTag(holder);
    } else {
      holder = (ColumnHolder) convertView.getTag();
    }

    if (hasNoData) {
      AbsListView.LayoutParams lp =
          new AbsListView.LayoutParams(getScreenWidth(), getScreenHeight() * 2 / 3);
      holder.noDataRootLayout.setLayoutParams(lp);
    } else {
      Column column = mDataList.get(position);
      ImgUitl.setImg(column.getColumn_cover(), holder.mImg);
      holder.mTitle.setText(column.getColumn_title());
      holder.mText.setText(column.getColumn_describe());
      holder.mTime.setText(column.getTime());
    }
    return convertView;
  }

  class ColumnHolder {

    public ColumnHolder() {
    }

    public ColumnHolder(View view) {
      ButterKnife.bind(this,view);
    }

    LinearLayout noDataRootLayout;
    @BindView(R.id.item_column_img) ImageView mImg;
    @BindView(R.id.item_column_title) TextView mTitle;
    @BindView(R.id.item_column_text) TextView mText;
    @BindView(R.id.item_column_time) TextView mTime;
  }
}
